Repository navigation
Conversation
`WasmBuffer` and `WasmBufferReader` declared `unsafe impl Send/Sync` on every target, over `Rc<RefCell<…>>`. That is sound only on single-threaded wasm32; native builds (the host unit-test lane) could move or share a buffer across threads, which is undefined behaviour. Gate the impls to wasm32 and back the buffer with `Arc<Mutex<…>>` off wasm32 so native gets `Send + Sync` from the compiler. wasm32 keeps `Rc<RefCell<…>>` and is unchanged apart from going through the same `lock_state` helper. `poll_recv` re-checks after registering its waker so a push from another thread can't be missed between read and registration. Adds a native test that pushes from another thread while a reader waits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJA9Zpan1vsursyFWHd
Member
Author
|
Closing without merging. The wasm adapter only runs in the browser. The native build exists only for the host unit-test lane ( If we ever want the native lane to be strictly sound, the cleaner route is to make the crate wasm32-only and move these tests to Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WasmBufferandWasmBufferReaderdeclareunsafe impl Send/Syncon every target, on top ofRc<RefCell<…>>. That is only sound on single-threaded wasm32. On native targets, which is how the host unit-test lane builds the crate, a buffer can be moved or shared across threads, and that is undefined behaviour.This PR is the soundness fix from #493 and nothing else:
unsafe impl Send/Syncfor both types now apply only on wasm32.Arc<Mutex<…>>. The traits requireSend + Sync, and on native the compiler now provides them. A smalllock_statehelper hides the difference. A poisoned lock is recovered instead of panicking, since the state is always consistent.Rc<RefCell<…>>. The only difference is thatsubscribeandpeeknow borrow mutably, which is harmless on a single thread.poll_recvreads again after registering its waker. Otherwise, on native, a push from another thread that lands between the read and the registration could be missed. On wasm32 the extra read only runs when the buffer is empty, and it costs very little.test_cross_thread_push_wakes_readerpushes 500 values from another thread while a reader waits withblock_on.Out of scope, compared with #493: the file moves, removing the guard that stops a native build with
wasm-runtimeon, and the new no-op time fallback.Related Issue
Checklist
make check). Not run in full. These ran locally:cargo test -p aimdb-wasm-adapter --no-default-features --lib, with and withoutobservability: passcargo clippy -D warningsfor the lib, native andwasm32-unknown-unknown(withwasm-runtimeandobservability): cleancargo fmt --check: cleanGenerated by Claude Code